define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	var app = require('mokit/app');
	var ContactView = require('../views/contact');
	var commonUtils = require('../common/utils');
	var Contact = require("../models/Contact");

	/**
	 * 社友录页面控制器
	 */
	return app.controller.create({
		isSetting: true,
		/**
		 * 默认action
		 */
		index: function(context) {
			var self = this;
			//清空返回处理队列
			commonUtils.backAction = [];
			Contact.getList(function(){
				self.setView(new ContactView({
					model: Contact
				}));
			});

		},

		//不用转到 group 页，用 prompt 在当前页完成添加即可
		addGroup: function(context) {
			var self = this;
			self.go(context, '/contact/group', '/contact');
		},
		
		addGroup2:function(context){
			context.view.prompt(context, '请输入分组名称', function(btnIndex) {
				if (btnIndex == 1) {

				}
			});
		},

		addUser:function(context){
			var me = this;
			context.view.prompt(context, '请输入要添加的用户', function(ops) {
				if (ops.buttonIndex == 1) {
					me.addUser2(context, ops.input1);
				}
			});
		},
		
		addUser2:function(context, id){
			Contact.addUser(id, function(){
				context.view.alert(context,"添加成功");
			});
		},		

		deleteUser: function(context, id) {
			var self = this;
			context.view.confirm(context, '确认删联系人吗？', function(btnIndex) {
				if (btnIndex == 1) {

				}
			});
		},

		startTalk: function(context, id, name) {
			var self = this;
			if (!window.imkit) {
				context.view.toast(context, '在浏览器中无法启动会话');
				return;
			}
			window.imkit.startTalk(id, '与' + name + '会话', function() {}, function() {
				context.view.toast(context, '启动会话失败');
			});
		}

	});

});